import { route } from 'quasar/wrappers';
import VueRouter from 'vue-router';
import { Store } from 'vuex';
import { StateInterface } from '../store';
import routes from './routes';
import storeInstance from 'src/store/index';
import { localStorage } from 'src/adapter/localstorage';
import { init } from 'src/utils/initStore';
/*
 * If not building with SSR mode, you can
 * directly export the Router instantiation
 */

// ...

export default route<Store<StateInterface>>(function({ Vue, store }) {
  Vue.use(VueRouter);
  console.log(process.env.VUE_ROUTER_MODE);

  const Router = new VueRouter({
    scrollBehavior: () => ({ x: 0, y: 0 }),
    routes,
    // Leave these as is and change from quasar.conf.js instead!
    // quasar.conf.js -> build -> vueRouterMode
    // quasar.conf.js -> build -> publicPath
    mode: process.env.VUE_ROUTER_MODE,
    base: process.env.VUE_ROUTER_BASE
  });

  Router.beforeEach((to, from, next) => {
    const visitor = localStorage.getItem('visitor');

    init(store);
    next();
  });
  return Router;
});
